﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Common;
using System.IO;
using System.Text;

/// <summary>
/// BindControl 的摘要说明
/// </summary>
public class BindControl
{
    public BindControl()
    {
        //
        // TODO: 在此处添加构造函数逻辑
        //
    }

    #region 日期
    /// <summary>
    /// 加载年份列表
    /// </summary>
    /// <param name="MyDrop">控件</param>
    /// <param name="IsInsert">是否插入“全部”</param>
    public void BindYearDropList(DropDownList MyDrop, bool IsInsert)
    {
        int initYear = 2010;
        int currentYear = DateTime.Now.Year;

        MyDrop.Items.Clear();
        if (IsInsert)
        {
            MyDrop.Items.Add(new ListItem("-- Select year --", ""));
        }

        for (int i = initYear; i <= currentYear; i++)
        {
            MyDrop.Items.Add(new ListItem(i.ToString() + "", i.ToString()));
        }
    }
    /// <summary>
    /// 加载相应月份
    /// </summary>
    /// <param name="MyDrop">控件</param>
    /// <param name="IsInsert">是否插入“全部”</param>
    public void BindMonthDropList(DropDownList MyDrop, bool IsInsert)
    {
        MyDrop.Items.Clear();
        if (IsInsert)
        {
            MyDrop.Items.Add(new ListItem("-- Select month --", ""));
        }

        for (int i = 1; i <= 12; i++)
        {
            MyDrop.Items.Add(new ListItem(i.ToString() + "", i.ToString()));
        }
    }

    /// <summary>
    /// 加载小时列表
    /// </summary>
    /// <param name="MyDrop"></param>
    /// <param name="IsInsert"></param>
    public void BindHoursDropList(DropDownList MyDrop, bool IsInsert)
    {
        MyDrop.Items.Clear();
        if (IsInsert)
        {
            MyDrop.Items.Add(new ListItem("--全部--", ""));
        }

        for (int i = 0; i < 24; i++)
        {
            MyDrop.Items.Add(new ListItem(i.ToString() + "时", i.ToString()));
        }
    }
    /// <summary>
    /// 加载分钟列表
    /// </summary>
    /// <param name="MyDrop"></param>
    /// <param name="IsInsert"></param>
    public void BindMinutesDropList(DropDownList MyDrop, bool IsInsert)
    {
        MyDrop.Items.Clear();
        if (IsInsert)
        {
            MyDrop.Items.Add(new ListItem("--全部--", ""));
        }

        for (int i = 0; i < 60; i++)
        {
            MyDrop.Items.Add(new ListItem(i.ToString() + "分", i.ToString()));
        }
    }

    /// <summary>
    /// 加载年份列表
    /// </summary>
    /// <param name="MyDrop">控件</param>
    /// <param name="IsInsert">是否插入“全部”</param>
    public void BindYearSelectList(HtmlSelect MyDrop, bool IsInsert)
    {
        int initYear = 2010;
        int currentYear = DateTime.Now.Year;

        MyDrop.Items.Clear();
        if (IsInsert)
        {
            MyDrop.Items.Add(new ListItem("--全部--", ""));
        }

        for (int i = initYear; i <= currentYear; i++)
        {
            MyDrop.Items.Add(new ListItem(i.ToString() + "年", i.ToString()));
        }
    }
    /// <summary>
    /// 加载相应月份
    /// </summary>
    /// <param name="MyDrop">控件</param>
    /// <param name="IsInsert">是否插入“全部”</param>
    public void BindMonthSelectList(HtmlSelect MyDrop, bool IsInsert)
    {
        MyDrop.Items.Clear();
        if (IsInsert)
        {
            MyDrop.Items.Add(new ListItem("--全部--", ""));
        }

        for (int i = 1; i <= 12; i++)
        {
            MyDrop.Items.Add(new ListItem(i.ToString() + "月份", i.ToString()));
        }
    }

    /// <summary>
    /// 加载小时列表
    /// </summary>
    /// <param name="MyDrop"></param>
    /// <param name="IsInsert"></param>
    public void BindHoursSelectList(HtmlSelect MyDrop, bool IsInsert)
    {
        MyDrop.Items.Clear();
        if (IsInsert)
        {
            MyDrop.Items.Add(new ListItem("--全部--", ""));
        }

        for (int i = 0; i < 24; i++)
        {
            MyDrop.Items.Add(new ListItem(i.ToString() + "时", i.ToString()));
        }
    }
    /// <summary>
    /// 加载分钟列表
    /// </summary>
    /// <param name="MyDrop"></param>
    /// <param name="IsInsert"></param>
    public void BindMinutesSelectList(HtmlSelect MyDrop, bool IsInsert)
    {
        MyDrop.Items.Clear();
        if (IsInsert)
        {
            MyDrop.Items.Add(new ListItem("--全部--", ""));
        }

        for (int i = 0; i < 60; i++)
        {
            MyDrop.Items.Add(new ListItem(i.ToString() + "分", i.ToString()));
        }
    }
    #endregion

    #region 系统枚举
    /// <summary>
    /// 枚举类型
    /// </summary>
    /// <param name="MyDrop"></param>
    /// <param name="IsInsert"></param>
    public void BindEnumItems_DropDownList(DropDownList MyDrop, string enumKey, bool defaultItem)
    {
        MyDrop.Items.Clear();
        if (defaultItem)
        {
            MyDrop.Items.Add(new ListItem("-- Select --", ""));
        }

        DataTable dat = new DataTable();
        if (!FilterHandler.ExistBadWord(enumKey))
            dat = BLL.Search.CommonSearch.ExecSelect("EnumItem",
                          new string[] { "EnumText, EnumValue" },
                          new string[] { "EnumKey" },
                          new string[] { "Equal" },
                          new string[] { "'" + enumKey + "'" },
                          new string[] { "SortIndex" },
                          new string[] { "ASC" });

        foreach (DataRow dr in dat.Select(""))
        {
            MyDrop.Items.Add(new ListItem(dr["EnumText"].ToString(), dr["EnumValue"].ToString()));
        }
    }

    /// <summary>
    /// 枚举成员 
    /// </summary>
    /// <param name="MyDrop"></param>
    /// <param name="IsInsert"></param>
    public void BindEnumItems_HtmlSelect(HtmlSelect MyDrop, string enumKey, bool defaultItem)
    {
        MyDrop.Items.Clear();
        if (defaultItem)
        {
            MyDrop.Items.Add(new ListItem("-- Select --", ""));
        }

        DataTable dat = new DataTable();
        if (!FilterHandler.ExistBadWord(enumKey))
            dat = BLL.Search.CommonSearch.ExecSelect("EnumItem",
                          new string[] { "EnumText, EnumValue" },
                          new string[] { "EnumKey" },
                          new string[] { "Equal" },
                          new string[] { "'" + enumKey + "'" },
                          new string[] { "SortIndex" },
                          new string[] { "ASC" });

        foreach (DataRow dr in dat.Select(""))
        {
            MyDrop.Items.Add(new ListItem(dr["EnumText"].ToString(), dr["EnumValue"].ToString()));
        }
    }
    #endregion
}
